package org.tlipoca.smuserhistory.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.genntii.smcommon.constant.GatewayConstant;
import org.genntii.smcommon.result.Result;
import org.genntii.smdomain.dto.UserHistoryDTO;
import org.genntii.smdomain.entity.SteamStore;
import org.genntii.smdomain.vo.UserHistoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tlipoca.smuserhistory.service.UserHistoryService;

import java.util.ArrayList;

@Tag(name = "用户历史接口")
@Slf4j
@RestController
@RequestMapping("/user_history")
public class UserHistoryController {

    @Autowired
    private UserHistoryService userHistoryService;

    @Operation(summary = "查询用户文章浏览历史")
    @GetMapping("/article")
    public Result<ArrayList<UserHistoryVO>> getUserArticleHistoryList(@RequestParam(value = "keyword",required = false) String keyword, HttpServletRequest request) {
        Long userId = Long.valueOf(request.getHeader(GatewayConstant.USER_ID));
        return Result.success(userHistoryService.getUserArticleHistoryListService(keyword, userId));
    }

    @Operation(summary = "查询用户库存浏览历史")
    @GetMapping("/store")
    public Result<ArrayList<SteamStore>> getUserStoreHistoryList(@RequestParam(value = "keyword",required = false) String keyword, HttpServletRequest request) {
        Long userId = Long.valueOf(request.getHeader(GatewayConstant.USER_ID));
        return Result.success(userHistoryService.getUserStoreHistoryListService(keyword, userId));
    }

    @Operation(summary = "新增用户历史")
    @PostMapping
    public Result addUserHistory(@RequestBody UserHistoryDTO userHistoryDTO, HttpServletRequest request) {
        Long userId = Long.valueOf(request.getHeader(GatewayConstant.USER_ID));
        userHistoryService.addUserHistoryService(userId, userHistoryDTO);
        return Result.success();
    }
}
